package com.info.zhiduoduo.alipay.constant;

import com.info.zhiduoduo.common.constants.EnumFindHelper;

/**
 * 支付宝转账,代付等订单状态值
 * <p> 订单状态 1:CREATE新建 2:SUCCESS成功 3:WAIT_PAY等待支付 4:CLOSED订单超时关闭
 */
public enum AlipayOrderStatusEnum {

	UNKOWN(0, "UNKOWN"),
	/**
	 * 新建订单
	 */
	CREATE(1, "CREATE"),
	/**
	 * 转账成功
	 */
	SUCCESS(2,"SUCCESS"),
	/**
	 * 等待支付
	 */
	WAIT_PAY(3, "WAIT_PAY"),
	/**
	 * 订单超时关闭
	 */
	CLOSED(4, "CLOSED"),
	/**
	 * 失败（适用于"单笔转账到银行卡"）
	 */
	FAIL(5, "FAIL"),
	/**
	 * 处理中（适用于"单笔转账到银行卡"）
	 */
	DEALING(6, "DEALING"),
	/**
	 * 退票（适用于"单笔转账到银行卡"）
	 */
	REFUND(7, "REFUND"),
	/**
	 * 订单不存在
	 */
	NOT_EXIST(8, "ORDER_NOT_EXIST"),
	;

	public int id;
	public String code;

	AlipayOrderStatusEnum(int id, String code) {
		this.id = id;
		this.code = code;
	}

	//####################################### 方便查找枚举值的方法 ###################################//

	static final EnumFindHelper<AlipayOrderStatusEnum, Integer> IdHelper = new EnumFindHelper<>(AlipayOrderStatusEnum.class, e -> e.id);

	static final EnumFindHelper<AlipayOrderStatusEnum, String> CodeHelper = new EnumFindHelper<>(AlipayOrderStatusEnum.class, e -> e.code);

	public static AlipayOrderStatusEnum findById(int id) {
		return IdHelper.find(id, UNKOWN);
	}

	public static AlipayOrderStatusEnum findByCode(String name) {
		return CodeHelper.find(name, UNKOWN);
	}
}
